/*
 * ﻿Copyright (C) 2011-2013 NewMain Softech
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package com.newmainsoftech.aspectjutil.eventmanager;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import com.newmainsoftech.aspectjutil.eventmanager.label.EventTrigger;

/**
 * Container of information of triggered event
 * 
 * @author <a href="mailto:artymt@gmail.com">Arata Y.</a>
 */
public class EventInfo {
	protected final Class<?> triggeredEvent;
	public final Class<?> getTriggeredEvent() {
		return triggeredEvent;
	}

	public static enum EventerType {
		Method, Field;
	}
	
	/**
	 * Container of information of eventer what supposes to be annotated with {@link EventTrigger} 
	 * 
	 * @author <a href="mailto:artymt@gmail.com">Arata Y.</a>
	 */
	public static class EventerInfo {
		protected final Object eventerObj;	// Actual object yield event
		protected final Method eventerMethod;
		protected final Field eventerField;
		protected final EventerType eventerType;
		
		// Constructors ---------------------------------------------------------------------------
		public EventerInfo( Object eventerObj, Method eventerMethod) {
			this.eventerObj = eventerObj;
			this.eventerMethod = eventerMethod;
			this.eventerField = null;
			this.eventerType = EventerType.Method;
		}
		public EventerInfo( Object eventerObj, Field eventerField) {
			this.eventerObj = eventerObj;
			this.eventerField = eventerField;
			this.eventerMethod = null;
			this.eventerType = EventerType.Field;
		}
		// ----------------------------------------------------------------------------------------
		
		// Getters --------------------------------------------------------------------------------
		public final Object getEventerObj() {
			return eventerObj;
		}
		public final Method getEventerMethod() {
			return eventerMethod;
		}
		public final Field getEventerField() {
			return eventerField;
		}
		public final EventerType getEventerType() {
			return eventerType;
		}
		// ----------------------------------------------------------------------------------------
	} // static class EventerInfo
	
	protected final EventerInfo eventerInfo;
	public final EventerInfo getEventerInfo() {
		return eventerInfo;
	}

	protected final Object result;
	public final Object getResult() {
		return result;
	}
	
	protected final Object[] args;
	public final Object[] getArgs() {
		return args;
	}
	
	protected final long threadId;
	public final long getThreadId() {
		return threadId;
	}


	public EventInfo( Class<?> triggeredEvent, EventerInfo eventerInfo, Object[] args, Object result) {
		this.triggeredEvent = triggeredEvent;
		this.eventerInfo = eventerInfo;
		this.args = args;
		this.result = result;
		threadId = Thread.currentThread().getId();
	}
}
